#include "ListBullet.h"


CListBullet::CListBullet(void)
{
}


CListBullet::~CListBullet(void)
{
}

CListBullet::CListBullet(int MaxBullet)
{
	_MaxBullet = MaxBullet;
	for(int i = 0; i < MaxBullet; i++)
	{
		_BulletPool.push(new CNewBullet());
	}
}

void CListBullet::Shoot(int X, int Y, int TimeAlive, float VectorX, float VecTorY, int TypeBullet)
{
	if(_BulletPool.size() != 0)
	{
		CNewBullet *temp = _BulletPool.front();
		temp->SetNewBullet(X, Y, TimeAlive, VectorX, VecTorY, TypeBullet);
		_ShootedBullet.push_back(temp);
		_BulletPool.pop();
	}
}

void CListBullet::Render()
{
	for(int i = 0; i < _ShootedBullet.size(); i++)
	{
		if(_ShootedBullet[i]->CheckALive())
		{
			_ShootedBullet[i]->Update();
			_ShootedBullet[i]->Render();
		}
		else
		{
			_ShootedBullet[i]->Reset();
			_BulletPool.push(_ShootedBullet[i]);
			_ShootedBullet.erase(_ShootedBullet.begin() + i);
		}
	}
}

std::vector<D3DXVECTOR2> CListBullet::GetBulletsPostion()
{
	std::vector<D3DXVECTOR2> BulletsPosition;
	for(int i = 0; i < _ShootedBullet.size(); i++)
	{
		BulletsPosition.push_back(_ShootedBullet[i]->GetPostion());
	}
	return BulletsPosition;
}

void CListBullet::SetMaxBullet(int MaxBullet)
{
	if(_MaxBullet < MaxBullet)
	{
		for(int i = 0; i < MaxBullet - _MaxBullet; i++)
		{
			_BulletPool.push(new CNewBullet());
		}
		_MaxBullet = MaxBullet;
	}
	else
	{
		if(_MaxBullet > MaxBullet)
		{
			for(int i = 0; i < _MaxBullet - MaxBullet; i++)
		{
			_BulletPool.pop();
		}
		_MaxBullet = MaxBullet;
		}
	}
}